<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 
mm_showMyFileName(__FILE__);

$iCol = 1;
if( !isset( $categories_per_row )) {
	$categories_per_row = $this->get_cfg('mainpage_productsperow') ;
} else {
	$categories_per_row = 4;
}

$cellwidth = intval( 100 / $categories_per_row );

if( empty( $categories )) {
	return; // Do nothing, if there are no child categories!
}
?>

<div class="ssmed_relatet_product">
<?php
foreach( $categories as $category ) {
	if ($iCol == 1) { // this is an indicator wether a row needs to be opened or not
		echo "<div style=\"width:100%;\">";
	}
	?>
	<div style="text-align:center;float:left;width:<?php echo $cellwidth;?>%">	
	<div class="ssmed_mainpage_product_categories_rb"> 
	<div class="ssmed_mainpage_product_categories_lb">
	<div class="ssmed_mainpage_product_categories_rt"> 
	<div class="ssmed_mainpage_product_categories_lt">
	<div class="ssmed_mainpage_product_categories_content">	
	<div class="category_name">
	<a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_virtuemart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>"> 
			<?php
            echo $category["category_name"];?></a>
            
            <a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_virtuemart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>"> 
			<?php
			echo $category['number_of_products'];?></a>
			</div>
            
         <a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_virtuemart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>"> 
			<?php
			if ( $category["category_thumb_image"] ) {
				echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
				echo "<br /><br/>\n";
			}?>
	</a>	 
	</div>
	</div>
	</div>
	</div>
	</div>
	</div>
	<?php
	// Do we need to close the current row now?
	if ($iCol == $categories_per_row) { // If the number of products per row has been reached
		echo "</div><div style=\"clear: both; height: 0;\"></div>";
		$iCol = 1;
	}
	else {
		$iCol++;
	}
}
// Do we need a final closing row tag?
if ($iCol != 1) {
	echo "</div><div style=\"clear: both; height: 0;\"></div>";
}
?>
</div>